﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace CRMAdapter
{
   public static class PayByPaymentHub
    {

       //Add customers to Payment Hub
       public static void AddCustomers(string digital_key, string passphrase, string your_system_reference, string your_general_reference, string last_name, string first_name, string email_address, string mobile_phone_number, string address_line1, string address_line2, string address_suburb, string address_state, string address_postcode, bool customer_pays_txn_fee, bool customer_pays_merchant_fee, string username, string bank_account_name, string bank_account_bsb, string bank_account_number)
       {
          
           PaymentHubServices.PaymentHubPaymentHubPortClient pc = new PaymentHubServices.PaymentHubPaymentHubPortClient();
           PaymentHubServices.V3ReturnStruct rs = pc.AddCustomer(digital_key, passphrase, your_system_reference, your_general_reference, last_name, first_name, email_address, mobile_phone_number, address_line1, address_line2, address_suburb, address_state, address_postcode, customer_pays_txn_fee, customer_pays_txn_fee, username);
           string message = "Status is: " + rs.code + " and system id is: " + rs.system_id;
           HttpContext.Current.Response.Write("<script type='text/javascript' language='javascript'>alert('" + message + "');</script>");

           if (rs.code == "HB")
           {
               pc.SetCustomerBankAccount(digital_key,passphrase,"",your_system_reference,bank_account_name,bank_account_bsb,bank_account_number,username);
               HttpContext.Current.Response.Redirect("AddPayment.aspx");

           }

            else
          {
              HttpContext.Current.Response.Write("<script type='text/javascript' language='javascript'>alert('Oops something went wrong');</script>");
            
          }


          

       }

       //Add payments in PaymentHub
       public static void AddPayments(string digital_key, string passphrase, string system_customer_id, string your_system_reference, string payment_reference, string payment_amount_in_cents, string debit_date, string username)
       {
           PaymentHubServices.PaymentHubPaymentHubPortClient pc = new PaymentHubServices.PaymentHubPaymentHubPortClient();
           PaymentHubServices.V3ReturnStruct rs = pc.AddPayment(digital_key, passphrase, system_customer_id, your_system_reference, payment_reference, payment_amount_in_cents, debit_date, username);
           if (rs.code == "W")
           {
               string message="Status: " + rs.code + " and system id is: " + rs.system_id;

               HttpContext.Current.Response.Write("<script type='text/javascript' language='javascript'>alert('" + message + "');</script>");

               HttpContext.Current.Response.Redirect("GetPaymentResult.aspx");
           }
           else
           {

               HttpContext.Current.Response.Write("<script type='text/javascript' language='javascript'>alert('Oops something went wrong');</script>");
           }


       }


       //Get payment status
       public static void GetPaymentResults(string digital_key, string passphrase, string system_payment_id, string payment_reference)
       {
           PaymentHubServices.PaymentHubPaymentHubPortClient pc = new PaymentHubServices.PaymentHubPaymentHubPortClient();
           PaymentHubServices.V3PaymentDetailStruct rs = pc.GetPaymentDetail(digital_key,passphrase,system_payment_id,payment_reference);

           string message = "Your payment status is: " + rs.payment_status + "\\n" + "Your system reference is:" + rs.your_system_reference + "\\n" + "Payment reference is:" + rs.payment_reference + "\\n" + "Payment amount in cents:" + rs.payment_amount_in_cents + "\\n" + "Debit date is:" + rs.debit_date + "\\n" + "Settlement date is:" + rs.settlement_date + "\\n" + "Payment Method:" + rs.payment_method + "\\n" + "Bank return code:" + rs.bank_return_code + "\\n" + "Transaction fee:" + rs.transaction_fee_client + "\\n" + "Payment id:"+rs.payment_id;
           HttpContext.Current.Response.Write("<script type='text/javascript' language='javascript'>alert('" + message + "');</script>");

       }

       
    }
}
